package org.example.friend.controller.user;

import org.example.common.core.constants.HttpConstants;
import org.example.common.core.controller.BaseController;
import org.example.common.core.model.Result;
import org.example.common.core.model.vo.LoginUserVO;
import org.example.friend.model.user.dto.UserDTO;
import org.example.friend.model.user.dto.UserUpdateDTO;
import org.example.friend.model.user.vo.UserVO;
import org.example.friend.service.user.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author : [Pashm]
 * @version : [v1.0]
 */
@RestController
@RequestMapping("/user")
public class UserController extends BaseController {

    @Autowired
    private IUserService userService;

    @PostMapping("/sendCode")
    private Result<Void> sendCode(@RequestBody UserDTO userDTO){
          return toResult(userService.sendCode(userDTO));
    }

    @PostMapping("/code/login")
    private Result<String> codeLogin(@RequestBody UserDTO userDTO){
         return Result.ok(userService.codeLogin(userDTO.getPhone(),userDTO.getCode()));
    }

    @DeleteMapping("/login")
    public Result<Void> logout(@RequestHeader(HttpConstants.AUTHENTICATION) String token){
        return toResult(userService.logout(token));
    }

    @GetMapping("/info")
    public Result<LoginUserVO> info(@RequestHeader(HttpConstants.AUTHENTICATION) String token){
        return userService.info(token);
    }

    @GetMapping("/detail")
    public Result<UserVO> detail(){
        return Result.ok(userService.detail());
    }

    @PutMapping("/edit")
    public Result<Void> edit(@RequestBody UserUpdateDTO userUpdateDTO){
        return toResult(userService.edit(userUpdateDTO));
    }

    @PutMapping("/head-image/update")
    public Result<Void> updateHeadImage(@RequestBody UserUpdateDTO userUpdateDTO){
        return toResult(userService.updateHeadImage(userUpdateDTO.getHeadImage()));

    }
}
